package managers
{
	import arens.Arena;
	import arens.EnumArens;
	import arens.PlayArena;
	
	import base.AreaBase;
	
	import events.EnumEvents;
	
	import starling.display.DisplayObject;
	import starling.display.Image;
	import starling.display.Sprite;
	import starling.events.Event;
	
	import utils.LoaderResource;

	public class LoaderArens
	{
		private var bg_loader:Image;
		private var _parentArena:Sprite;
		public var arena:AreaBase;
		
		public function LoaderArens(nameArena:String,parentArena:Sprite)
		{
			_parentArena = parentArena;
			bg_loader = new Image(LoaderResource.instance.assetManager.getTexture("Loader"));
			parentArena.addChild(bg_loader);
			
			while(parentArena.numChildren>0){
				parentArena.removeChildAt(0,true);
			}
			switch(nameArena){
				case EnumArens.MAIN_SCREEN:{
					arena = new Arena(nameArena) as AreaBase;
					break;
				}
				case EnumArens.PLAY_SCREEN:{
					arena = new PlayArena(nameArena) as AreaBase;
					break;
				}
					
				default:{
					arena = new Arena(nameArena) as AreaBase;
					break;
				}
			}
			
			arena.addEventListener(EnumEvents.FINISH_LOAD_ARENA,onFinishLoadArena);
			arena.load();
		}
		private function onFinishLoadArena(e:Event):void{
			arena.removeEventListener(EnumEvents.FINISH_LOAD_ARENA,onFinishLoadArena);
			arena.initial();
			_parentArena.removeChild(bg_loader);
			_parentArena.addChild(arena);
		}
	}
}